﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
 
using BOHVote.BLL;
using BOHVote.Entity;

namespace BOH.AccreditationSystem
{
    public partial class InterviewQuestionsPrint : System.Web.UI.Page
    {
        private BHUser user;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["User"] != null)
                //{
                //    user = (BHUser)Session["User"];
                //    switch (user.RightType)
                //    {
                //        case "S":
                //            LoadSubject(user.RightCode);
                //            break;
                //        case "Q":
                //        case "C":
                //        case "A":
                //            LoadSubject(string.Empty);
                //            break;
                //    }
                //}
                if (Request.QueryString["SubjectID"] != null)
                {
                    LoadSubjectA(Request.QueryString["SubjectID"].ToString());
                }
            }
        }

        private void LoadSubjectA(string subjectID)
        {
            
            if (!String.IsNullOrEmpty(subjectID))
            {
                DataSet dst = new DataSet();
                labNoRecord.Text = string.Empty;
                DataTable dt = new DataTable();
                DataColumn dc1 = new DataColumn("SubjectName");
                dt.Columns.Add(dc1);
                DataColumn dc2 = new DataColumn("SubjectID");
                dt.Columns.Add(dc2);
                string period = string.Empty;
                if (Request.QueryString["period"] != null && !String.IsNullOrEmpty(Request.QueryString["period"].ToString()))
                {
                    period = Request.QueryString["period"];
                }
                else
                {
                    period = (string)Session["ApplyPeriod"];
                }
                DataSet dstQ = InterviewClass.getQuestions(string.Empty, subjectID, string.Empty, "A", period);
                if (dstQ != null && dstQ.Tables.Count > 0 && dstQ.Tables[0].Rows.Count > 0)
                {
                    DataRow dr1 = dt.NewRow();
                    dr1["SubjectName"] = Subject.getSubjectNameBySubjectID(subjectID);
                    dr1["SubjectID"] = subjectID;
                    dt.Rows.Add(dr1);
                }
                dst.Tables.Add(dt);
                RepAll.DataSource = dst;
                RepAll.DataBind();
            }
            else
            {
                labNoRecord.Text = "该学科组未录入题目.";
            }

        }

        private void LoadSubject(string subjectID)
        {
            DataSet dstall = new DataSet();
            if (!String.IsNullOrEmpty(subjectID))
                dstall = Subject.getAllSpecialityBySubjectID(subjectID);
            else
                dstall = Subject.getAllASubject();
            if (dstall.Tables[0].Rows.Count > 0)
            {
                labNoRecord.Text = string.Empty;
                DataSet dstR = new DataSet();
                DataTable dt = new DataTable();
                DataColumn dc1 = new DataColumn("SubjectName");
                dt.Columns.Add(dc1);
                DataColumn dc2 = new DataColumn("SubjectID");
                dt.Columns.Add(dc2);
                foreach (DataRow dr in dstall.Tables[0].Rows)
                {
                    DataSet dstQ = InterviewClass.getQuestions(string.Empty, dr["SubjectID"].ToString(), string.Empty, "A", (string)Session["ApplyPeriod"]);
                    if (dstQ != null && dstQ.Tables.Count > 0 && dstQ.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr1 = dt.NewRow();
                        dr1["SubjectName"] = Subject.getSubjectNameBySubjectID(dr["SubjectID"].ToString());
                        dr1["SubjectID"] = dr["SubjectID"].ToString();
                        dt.Rows.Add(dr1);
                    }
                }
                dstR.Tables.Add(dt);
                RepAll.DataSource = dstR;
                RepAll.DataBind();
            }
            else
            {
                labNoRecord.Text = "该学科组未录入题目.";
            }
        }

        protected void RepAll_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                HiddenField hidVale = (HiddenField)e.Item.FindControl("hiddenSubjectID");
                string period = string.Empty;
                if (Request.QueryString["period"] != null && !String.IsNullOrEmpty(Request.QueryString["period"].ToString()))
                {
                    period = Request.QueryString["period"];
                }
                else
                {
                    period = (string)Session["ApplyPeriod"];
                }
                DataSet dst = InterviewClass.getQuestions(string.Empty, hidVale.Value, string.Empty, "A", period);
                Repeater r = (Repeater)e.Item.FindControl("RepQuestion");
                r.DataSource = dst;
                r.DataBind();
            }
        }
    }
}
